/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NWEB_DELEGATE_INTERFACE_H
#define NWEB_DELEGATE_INTERFACE_H

#include <functional>
#include <string>
#include "cef_delegate/nweb_inputmethod_client.h"
#include "display_manager_adapter.h"
#include "nweb_download_callback.h"
#include "nweb_preference.h"
#include "nweb_handler.h"

namespace OHOS::NWeb {
class NWebDelegateInterface
  : public std::enable_shared_from_this<NWebDelegateInterface>{
 public:
  virtual ~NWebDelegateInterface() = default;

  virtual bool IsReady() = 0;
  virtual void OnDestroy(bool is_close_all) = 0;
  virtual void RegisterDownLoadListener(
      std::shared_ptr<NWebDownloadCallback> downloadListener) = 0;
  virtual void RegisterNWebHandler(std::shared_ptr<NWebHandler> handler) = 0;
  virtual void RegisterRenderCb(
      std::function<void(const char*)> render_update_cb) = 0;
  virtual void SetInputMethodClient(
      CefRefPtr<NWebInputMethodClient> client) = 0;

  /* event interface */
  virtual void Resize(uint32_t width, uint32_t height) = 0;
  virtual void OnTouchPress(int32_t id, double x, double y) = 0;
  virtual void OnTouchRelease(int32_t id, double x, double y) = 0;
  virtual void OnTouchMove(int32_t id, double x, double y) = 0;
  virtual void OnTouchCancel() = 0;
  virtual bool SendKeyEvent(int32_t keyCode, int32_t keyAction) = 0;
  virtual void SendMouseWheelEvent(double x, double y, double deltaX, double deltaY) = 0;
  virtual void SendMouseEvent(int x, int y, int button, int action) = 0;
  virtual void NotifyScreenInfoChanged(RotationType rotation,
                                       OrientationType orientation) = 0;

  virtual void Load(const std::string& url) = 0;
  virtual bool IsNavigatebackwardAllowed() const = 0;
  virtual bool IsNavigateForwardAllowed() const = 0;
  virtual bool CanNavigateBackOrForward(int numSteps) const = 0;
  virtual void NavigateBack() const = 0;
  virtual void NavigateForward() const = 0;
  virtual void NavigateBackOrForward(int32_t step) const = 0;
  virtual void DeleteNavigateHistory() = 0;
  virtual void Reload() const = 0;
  virtual void ReloadOriginalUrl() const = 0;
  virtual void Zoom(float zoomFactor) const = 0;
  virtual bool ZoomIn() const = 0;
  virtual bool ZoomOut() const = 0;
  virtual void Stop() const = 0;
  virtual void ExecuteJavaScript(const std::string& code) const = 0;
  virtual void ExecuteJavaScript(
      const std::string& code,
      std::shared_ptr<NWebValueCallback<std::string>> callback) const = 0;
  virtual void PutBackgroundColor(int color) const = 0;
  virtual void InitialScale(float scale) const = 0;
  virtual void OnPause() = 0;
  virtual void OnContinue() = 0;
  virtual std::shared_ptr<NWebPreference> GetPreference() const = 0;
  virtual std::string Title() = 0;
  virtual HitTestResult GetHitTestResult() const = 0;
  virtual int PageLoadProgress() = 0;
  virtual float Scale() = 0;
  virtual void Load(
      std::string& url,
      std::map<std::string, std::string> additionalHttpHeaders) = 0;
  virtual void LoadWithDataAndBaseUrl(const std::string& baseUrl,
                                      const std::string& data,
                                      const std::string& mimeType,
                                      const std::string& encoding,
                                      const std::string& historyUrl) = 0;
  virtual void LoadWithData(const std::string& data,
                            const std::string& mimeType,
                            const std::string& encoding) = 0;
  virtual int ContentHeight() = 0;
  virtual void RegisterArkJSfunction(
      const std::string& object_name,
      const std::vector<std::string>& method_list) const = 0;
  virtual void UnregisterArkJSfunction(
      const std::string& object_name,
      const std::vector<std::string>& method_list) const = 0;
  virtual void RegisterNWebJavaScriptCallBack(
      std::shared_ptr<NWebJavaScriptResultCallBack> callback) = 0;
  virtual void OnFocus() const = 0;
  virtual void OnBlur() const = 0;
};
}  // namespace OHOS::NWeb

#endif  // nweb_delegate_INTERFACE_H
